package com.huangbc.verificationcode.controller;

import com.huangbc.internalcommon.dto.ResponseResult;
import com.huangbc.internalcommon.response.NumberCodeResponse;
import com.huangbc.internalcommon.util.RandomUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;

/**
 * @Author: Derek.huang on 2024/3/28 8:45.
 */
@RestController
public class NumberCodeController {


//    @Value("${spring.cloud.nacos.discovery.cluster-name}")
//    private String clusterName;

    @Value("${server.port}")
    private String port;

    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size , HttpServletRequest request){

        String tag = request.getHeader("tag");
        System.out.println("验证码服务收到的tag："+tag);

        System.out.println("收到的验证码:" + port);
        // 生成验证码
        String randomNum = RandomUtils.getRandomNum(size);
//        System.out.println("数据中心，区域："+clusterName);

        // 定义返回值
        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode(randomNum);
        return ResponseResult.success(response);
    }

}

